package item

import (
	"gddgame.cc/galaxy/common/dsl/game"
	"gddgame.cc/galaxy/common/dsl/game/attr"
	"gddgame.cc/galaxy/utils"
)

//go:generate msgp

type ItemType byte
type CoinType byte

//msgp:tuple Item
type Item struct {
	Id    int      `json:"id"  msg:"id"`
	Name  string   `json:"name" msg:"name"`
	Desc  string   `json:"desc" msg:"desc"`
	Icon  string   `json:"icon" msg:"icon"`
	Type  ItemType `json:"type" msg:"type"`
	Level int      `json:"level" msg:"level"`
	// 是否是消耗类型
	IsConsume bool `json:"is_consume" msg:"is_consume"`
	// 最大堆叠数
	Max int `json:"max" msg:"max"`
	// 售卖货币类型
	CoinType CoinType `json:"coin_type" msg:"coin_type"`

	// todo delete
	BuyPrice int `json:"buy_price" msg:"buy_price"`
	// 售卖价格
	SellPrice int `json:"sell_price" msg:"sell_price"`

	// todo delete
	SkillId int `json:"skill_id" msg:"skill_id"`

	// todo delete
	Attr attr.AttrEffectSlice `json:"attr" msg:"attr"`

	Extend interface{} `json:"extend" msg:"extend"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewItem(provider *game.DataProvider, item *SettingItem) *Item {
	extend := game.NewDataExtend(utils.ToString(item.Id), item.UpdateTime).Add("name", item.Name).Add("desc", item.Desc)
	ext := &Item{
		Id:        item.Id,
		Name:      provider.LanguageKey(extend.Inline(), "name"),
		Desc:      provider.LanguageKey(extend.Inline(), "desc"),
		Icon:      item.Icon,
		Type:      item.Type,
		Level:     item.Level,
		IsConsume: item.IsConsume,
		Max:       item.Max,
		CoinType:  item.CoinType,
		BuyPrice:  0,
		SellPrice: item.SellPrice,
		SkillId:   0,
		Attr:      nil,
		Extend:    item.Extend,

		DataExtend: extend,
	}
	return ext
}

//msgp:tuple ShopItem
type ShopItem struct {
	Id     int `json:"id" msg:"id"`
	Number int `json:"number" msg:"number"`
	// 购买价格
	BuyPrice int   `json:"buy_price" msg:"buy_price"`
	Item     *Item `json:"item" msg:"item"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewShopItem(provider *game.DataProvider, shopItem *SettingShopItem, item *Item) *ShopItem {
	ext := &ShopItem{
		Id:       shopItem.Id,
		Number:   shopItem.Number,
		BuyPrice: shopItem.BuyPrice,
		Item:     item,

		DataExtend: game.NewDataExtend(utils.ToString(shopItem.Id), shopItem.UpdateTime),
	}
	return ext
}
